package com.mvd.app.ac2021.activitys;

import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;
import com.kongzue.dialog.v3.TipDialog;
import com.kongzue.dialog.v3.WaitDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.ac2020.VideoListActivity;
import com.mvd.app.activity.BaseActivity;
import com.mvd.app.activity.WaiJianPhotoActivity;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.Utils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.BuHeGeModel3;
import com.mvd.app.model.CarItemEndModel;
import com.mvd.app.model.CarItemStartModel;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.CheckItemModel;
import com.mvd.app.model.CodeListModel;
import com.mvd.app.model.Item_2Model;
import com.mvd.app.model.ItemsModel;
import com.mvd.app.model.OutPhotoItem;
import com.mvd.app.model.ReportedModel;
import com.mvd.app.model.StationInforModel;
import com.mvd.app.model.TianjinReportModel;
import com.mvd.app.model.TypeModel;
import com.mvd.app.model.UpdateCarStatusModel;
import com.mvd.app.model.WaiJainDataModel;
import com.mvd.app.model.WaiJianAddRecordModel;
import com.mvd.app.model.WaiJianItemModel;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.mvd.app.application.BaseApplication.myChoiceModelList;
import static com.mvd.app.application.BaseApplication.mycar_checkItemlList;

/**
 * 外检 车辆详情 页面
 */

public class WaiJianActivity extends BaseActivity {

    @BindView(R.id.ac_waijian_number)
    TextView acWaijianNumber;
    @BindView(R.id.ac_waijian_SN)
    TextView acWaijianSN;
    @BindView(R.id.ac_waijian_times)
    TextView acWaijianTimes;
    @BindView(R.id.ac_waijian_line)
    TextView acWaijianLine;

    @BindView(R.id.ac_waijian_details_video)
    Button acDetailsVideo;
    @BindView(R.id.ac_waijian_btn_other)
    Button acWaijianBtnOther;
    @BindView(R.id.ac_waijian_btn_start)
    Button acWaijianBtnStart;
    @BindView(R.id.ac_waijian_btn_haerbing_end)
    Button acWaijianBtnHaerbingEnd;
    @BindView(R.id.ac_waijian_details_waikuo_shipin_start)
    Button acWaijianDetailsWaikuoShipinStart;
    @BindView(R.id.ac_waijian_details_waikuo_shipin_end)
    Button acWaijianDetailsWaikuoShipinEnd;
    @BindView(R.id.ac_waijian_details_waikuo_shipin)
    LinearLayout acWaijianDetailsWaikuoShipin;
    @BindView(R.id.ac_waijian_btn_report)
    Button acWaijianBtnReport;
    @BindView(R.id.ac_waijian_btn_report_new)
    Button acWaijianBtnReportNew;
    private int CHECK_MODE = 0;//检测模式 0:外检  1：路试 2：底盘动态
    private String Line = "01";//外检车道
    private String Item_Code = "";//F1外检,R1路试，DC底盘动态
    private String Login_name = "", login_IDNumber;//当前登录的检测员的名字
    private CarsInforModel carsInforModel;
    public WaiJianActivity instances = null;
    List<WaiJianAddRecordModel> WaiJianAddRecordModelList = new ArrayList<>();//外检增加记录list
    private StationInforModel stationInforModel;
    String up_json_str = "";
    private WaiJainDataModel waiJainDataModel = new WaiJainDataModel();//外检上传数据model
    private String EngineNOFlag,dzss,jianyi;
    private boolean Is_TianJing_Report = false;
    private TianjinReportModel tianjinReportModel;
    private List<TianjinReportModel> tianjinReportModels;
    private boolean isNewPlat = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_waijian);
        ButterKnife.bind(this);
        setBackBtn();
        setTopTitle("外检车辆详情");
        instances = this;
        String logStrf = "\n" + "onCreate-----外检车辆详情-----WaiJianActivity--" +dzss+ "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());

//        i_3.putExtra("model_CarsInforModel", carsInforModel);
//        i_3.putExtra("Car_Line", Line);
//        i_3.putExtra("login_w_name", Login_name);
//        i_3.putExtra("login_IDNumber", login_IDNumber);
        carsInforModel = (CarsInforModel) getIntent().getSerializableExtra("model_CarsInforModel");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        Login_name = getIntent().getExtras().getString("login_w_name", "");
        Line = getIntent().getExtras().getString("Car_Line", "");
        EngineNOFlag = getIntent().getExtras().getString("EngineNOFlag", "");
        jianyi = getIntent().getExtras().getString("jianyi", "");
        dzss = getIntent().getExtras().getString("dzss", "0");

        Log.e("tag", "WaiJianActivity-EngineNOFlag==" + EngineNOFlag);
        Log.e("tag", "WaiJianActivity-jianyi==" + jianyi);
        acWaijianLine.setText(Line);
        CHECK_MODE = BaseApplication.JIANCE_MODE;
//        switch (CHECK_MODE) {
//            case 0:
//                Item_Code = "ac_waijianF1";
//                break;
//            case 1:
//                Item_Code = "R1";
//                break;
//            case 2:
//                Item_Code = "DC";
//                break;
//        }
//
        if (carsInforModel != null) {
            //车牌号码
            if (!TextUtils.isEmpty(carsInforModel.getPlateRegion()) && !TextUtils.isEmpty(carsInforModel
                    .getPlateNO())) {
                acWaijianNumber.setText(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
            }
            //检验次数```````
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getTimes()))) {
                acWaijianTimes.setText(carsInforModel.getTimes() + "次");
            }
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getSN()))) {
                acWaijianSN.setText(carsInforModel.getSN());
            }


            if (SharedPreferencesUtils.getWaiKuoVideo(instances)) {
                acWaijianDetailsWaikuoShipin.setVisibility(View.VISIBLE);
            } else {
                acWaijianDetailsWaikuoShipin.setVisibility(View.GONE);
            }

//            //车身颜色
//            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getBodyColor())) && String.valueOf(carsInforModel.getBodyColor()) != "null") {
//                acVehicleCarColor.setText(VehicleCheckUtils.CarColorsFilter(carsInforModel
//                        .getBodyColor()));
//            }
        }

//        //哈尔滨地区--结束按钮
//        if (SharedPreferencesUtils.getHaErBinVersion(instances)) {
//            acWaijianBtnHaerbingEnd.setVisibility(View.VISIBLE);
//            getOutPhotoItem();
//            getStationInfor();
//            getMyCarItems();
//            initDataToHaerbin();
//        } else {
//            acWaijianBtnHaerbingEnd.setVisibility(View.GONE);
//        }

        if (SharedPreferencesUtils.getTianJinVersion(instances)) {
            acWaijianBtnReport.setVisibility(View.VISIBLE);
            acWaijianBtnReportNew.setVisibility(View.VISIBLE);
        } else {
            acWaijianBtnReport.setVisibility(View.GONE);
            acWaijianBtnReportNew.setVisibility(View.GONE);
        }

    }

    void initDataToHaerbin()  {
//给平台的数据赋值
        waiJainDataModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        waiJainDataModel.setGUID(carsInforModel.getGUID());
        waiJainDataModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(instances));
        waiJainDataModel.setBrakeForce(carsInforModel.getBrakeForce());
//                waiJainDataModel.setPlateNO(carsInforModel.getPlateNO());
        waiJainDataModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
        waiJainDataModel.setAirAdmission(carsInforModel.getAirAdmission());
        try {
            String name = URLDecoder.decode(Login_name, "UTF-8");

            waiJainDataModel.setAppearanceInspector(name);//检测员名字，汉字
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        UtilsLog.e("getIDNumber=44=" + BaseApplication.accountModelList.get(0).getIDNumber());
        UtilsLog.e("login_IDNumber=44=" + login_IDNumber);
//        waiJainDataModel.setAppearanceNo(BaseApplication.accountModelList.get(0).getIDNumber());
        waiJainDataModel.setAppearanceNo(login_IDNumber);
        waiJainDataModel.setApprovedLoad(carsInforModel.getApprovedLoad());
        waiJainDataModel.setArea(carsInforModel.getArea());
        waiJainDataModel.setBodyColor(carsInforModel.getBodyColor());
        waiJainDataModel.setBrand(carsInforModel.getBrand());
        waiJainDataModel.setCarBodyType(carsInforModel.getCarBodyType());
        waiJainDataModel.setCarID(carsInforModel.getCarID());
        waiJainDataModel.setCarModel(carsInforModel.getCarModel());
        waiJainDataModel.setCarTypeLevel(carsInforModel.getCarTypeLevel());
        waiJainDataModel.setCategory(carsInforModel.getCategory());
        waiJainDataModel.setCentralAxle(carsInforModel.getCentralAxle());
        waiJainDataModel.setCode(carsInforModel.getCode());
        waiJainDataModel.setCombCarNO(carsInforModel.getCombCarNO());
        waiJainDataModel.setCurbWeight(carsInforModel.getCurbWeight());
        waiJainDataModel.setDetectDate(carsInforModel.getDetectDate());
        waiJainDataModel.setDetectionCategory(carsInforModel.getDetectionCategory());
        waiJainDataModel.setDetectionStatus(carsInforModel.getDetectionStatus());
        waiJainDataModel.setDisplacement(carsInforModel.getDisplacement());
        waiJainDataModel.setDriveAxle(carsInforModel.getDriveAxle());
        waiJainDataModel.setDriverAxleWeight(carsInforModel.getDriverAxleWeight());
        waiJainDataModel.setDriverTypeName(carsInforModel.getDriverTypeName());
        waiJainDataModel.setDriverType(carsInforModel.getDriverType());
        waiJainDataModel.setPlateType(carsInforModel.getPlateType());
        waiJainDataModel.setItemcode(Item_Code);
        waiJainDataModel.setLine(Line);
        waiJainDataModel.setMainAxis(carsInforModel.getMainAxis());
        waiJainDataModel.setParkingAxle(carsInforModel.getParkingAxle());
        waiJainDataModel.setEngineNO(carsInforModel.getEngineNO());
        waiJainDataModel.setFuelType(carsInforModel.getFuelType());
        waiJainDataModel.setPlateTypeName(carsInforModel.getPlateTypeName());
        waiJainDataModel.setPlatformSN(carsInforModel.getPlatformSN());
        waiJainDataModel.setQueueID(carsInforModel.getQueueID());
        waiJainDataModel.setSN(carsInforModel.getSN());
        waiJainDataModel.setStatus(carsInforModel.getStatus());
        waiJainDataModel.setTest_times(carsInforModel.getTimes());
        waiJainDataModel.setType(carsInforModel.getType());
        waiJainDataModel.setVIN(carsInforModel.getVIN());
        waiJainDataModel.setDataType("F1");
        waiJainDataModel.setOutlineLength(carsInforModel.getOutlineLength());
        waiJainDataModel.setOutlineWidth(carsInforModel.getOutlineWidth());
        waiJainDataModel.setOutlineHeight(carsInforModel.getOutlineHeight());
    }

    @Override
    protected void onResume() {
        super.onResume();
        List<WaiJianItemModel> books = WaiJianItemModel.listAll(WaiJianItemModel.class);
        if (books != null && books.size() > 0) {
            UtilsLog.e("WaiJianActivity----本地数据库查询----不为空==" + books.toString());
        } else {
            UtilsLog.e("WaiJianActivity----本地数据库查询----空==");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        String logStrf = "\n" + "onDestroy-----外检车辆详情-----WaiJianActivity--" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        instances = null;
    }

    @OnClick({R.id.ac_waijian_line, R.id.ac_waijian_details_video,
            R.id.ac_waijian_btn_other, R.id.ac_waijian_btn_start
            , R.id.ac_waijian_btn_haerbing_end, R.id.ac_waijian_btn_report,R.id.ac_waijian_btn_report_new,
            R.id.ac_waijian_details_waikuo_shipin_start, R.id.ac_waijian_details_waikuo_shipin_end})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_waijian_btn_report:
                //天津---查询车辆报告
                tianJin_getCarReport();
                Is_TianJing_Report = true;
                break;
            case R.id.ac_waijian_btn_report_new:
                // 天津--新平台查询车辆公告
                isNewPlat = true;
                tianJin_getCarReport();
                Is_TianJing_Report = true;
                break;
            case R.id.ac_waijian_details_waikuo_shipin_start:
                //外扩视频录像开始
                waiKuoShiPinStart();
                break;
            case R.id.ac_waijian_details_waikuo_shipin_end:
                //外扩视频录像结束
                waiKuoShiPinEnd();
                break;
            case R.id.ac_waijian_btn_haerbing_end:
                //哈尔滨地区结束
                uploadPlatformData_w(waiJainDataModel);
                uploadPlatformData_w(waiJainDataModel);
                getDataReportData2();
                getDataReportData2();
                break;
            case R.id.ac_waijian_line:
                //检测线号
                showMyDialog(line_str, R.id.ac_waijian_line);
                break;
            case R.id.ac_waijian_details_video:
                Line = acWaijianLine.getText().toString().trim();
                Intent intent_video_1 = new Intent(instances, VideoListActivity.class);
                intent_video_1.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
                intent_video_1.putExtra("CarDetailsActivity_acCarDetailsWaijianchedao", Line);
                intent_video_1.putExtra("video_type", 1);
                intent_video_1.putExtra("CarDetailsActivity_Line", Line);
                intent_video_1.putExtra("flag", 0);
                startActivity(intent_video_1);
                break;
            case R.id.ac_waijian_btn_other:
                //外检项目--更新车辆信息
                Line = acWaijianLine.getText().toString().trim();
                Intent intent_3 = new Intent(instances, WaiJianItemActivity.class);
                intent_3.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
                intent_3.putExtra("CarDetailsActivity_Line", Line);
                intent_3.putExtra("login_w_name", Login_name);
                intent_3.putExtra("login_IDNumber", login_IDNumber);
                startActivity(intent_3);
                break;
            case R.id.ac_waijian_btn_start:
                //项目开始
                Line = acWaijianLine.getText().toString().trim();
//                Intent intent = new Intent(instances, WaiJianPhotoActivity.class);
//                intent.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
//                intent.putExtra("CarDetailsActivity_acCarDetailsWaijianchedao",
//                        Line);
//                intent.putExtra("CarDetailsActivity_Line", Line);
//                intent.putExtra("login_w_name", Login_name);
//                intent.putExtra("login_IDNumber", login_IDNumber);
//                startActivity(intent);
//                if (!TextUtils.isEmpty(Item_Code)) {
//                    if (CHECK_MODE == 0) {
                String str = "";

                if (SharedPreferencesUtils.getHeNanVersion(instances)) {
                    //河南地区  开始录像  按钮
                    str = "河南地区";
                    Intent intent = new Intent(instances, WaiJianPhotoActivity.class);
                    intent.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
                    intent.putExtra("CarDetailsActivity_acCarDetailsWaijianchedao",
                            Line);
                    intent.putExtra("CarDetailsActivity_Line", Line);
                    intent.putExtra("login_w_name", Login_name);
                    intent.putExtra("login_IDNumber", login_IDNumber);
                    intent.putExtra("start_time", BaseApplication.W_ItemStart_time);
                    intent.putExtra("EngineNOFlag", EngineNOFlag);
                    intent.putExtra("jianyi", jianyi);
                    intent.putExtra("dzss", dzss);
                    startActivity(intent);
                    finish();
                } else if (SharedPreferencesUtils.getTianJinVersion(instances)) {
                    str = "通用版--天津地区";
                    if (Is_TianJing_Report) {
                        getDataWaiJainStart();
                    } else {
                        TipDialog.show(instances, "未查询车辆报告", TipDialog.TYPE.WARNING);
                    }
                } else {
                    str = "通用版";
                    getDataWaiJainStart();
                }
//                if (SharedPreferencesUtils.getHaErBinVersion(instances)) {
//                    //哈尔滨地区  跳转第三方拍照
//                    str = "哈尔滨地区";
//                    getDataWaiJainStart();
//                    gotoApp();
//                }


                String logStr = "车牌号码：：" + carsInforModel.getPlateRegion() + carsInforModel
                        .getPlateNO() + "\n" + "动作：点击项目开始按钮-----" + str + "-----" + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                break;
        }
    }

    //跳转车管所app,目前只用于哈尔滨地区
    private void gotoApp() {
        UtilsLog.e("stationInforModel==" + stationInforModel.toString());
        String packageName = "com.dongma.takephotos.app";
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setComponent(new ComponentName(packageName, packageName + ".RequestAction"));
        intent.putExtra("jczmc", stationInforModel.getName());//检验机构名称
        intent.putExtra("clsbdh", carsInforModel.getVIN());//车辆识别代号
//        String[] str=carsInforModel.getPlateTypeName().split("-");
        intent.putExtra("hpzl", carsInforModel.getPlateType());//号牌种类
        intent.putExtra("hphm", carsInforModel.getPlateRegion() + carsInforModel.getPlateNO
                ());//车牌号码
        intent.putExtra("jylsh", carsInforModel.getPlatformSN());//查验流水号
        UtilsLog.e("外检-gotoApp-次数==" + carsInforModel.getTimes());
        intent.putExtra("jycs", carsInforModel.getTimes());//次数
        intent.putExtra("jcxdh", Line);//检测线代号
        intent.putExtra("jczbh", stationInforModel.getSecurityNO());//检验机构编号
        intent.putExtra("jyxm", "F1");//检验项目
        intent.putExtra("zpgs", up_json_str);
//        intent.putExtra("jkxlh","7E1D09090306170400158BCF86C988C78BCC8F9B818DE7EAFC98A2C7A49D636E");//接口序列号
        UtilsLog.e("getInterfaceNO==" + stationInforModel.getInterfaceNO());
        intent.putExtra("jkxlh", stationInforModel.getInterfaceNO());
        intent.putExtra("zdbs", CommonUtils.getIMEI(instances));//终端标识
        startActivityForResult(intent, 20);
    }

    /**
     * 获取检测站信息
     */
    private void getStationInfor() {
        UtilsLog.e("getStationInfor---url==" + SharedPreferencesUtils.getIP(instances) + JIAN_CE_ZHAN_INFOR);
        String logStr = "\n" + "获取检测站信息----url" + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + JIAN_CE_ZHAN_INFOR + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + JIAN_CE_ZHAN_INFOR).tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        //完成按钮可点击
//                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
                        String logStr = "\n" + "获取检测站信息----onSuccess" + "\n" +
                                "result::" + result + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        UtilsLog.e("getStationInfor-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getStationInfor-newResult==" + newResult);

                        String newResult2 = newResult.substring(1, newResult.length() - 1);
                        UtilsLog.e("getStationInfor-newResult2==" + newResult2);

                        stationInforModel = new StationInforModel();
                        stationInforModel = JsonUtil.fromJson(newResult2, StationInforModel.class);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("EndAllItem-onError==" + response.body());
                        String logStr = "\n" + "获取检测站信息----onError" + "\n" +
                                "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    private String[] line_str = new String[]{"1", "2", "3", "4", "5", "6"};
    //    private String[] line_str = new String[]{"01", "02", "03", "04", "05", "06"};
    private String[] fou_shi_str = new String[]{"否", "是"};

    private void showMyDialog(String[] str, final int id) {
//        BottomMenu bottomMenu= BottomMenu().build(this);
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("外检---showMyDialog==" + text + "===" + index);
                switch (id) {
                    case R.id.ac_waijian_line:
                        // 线号
                        acWaijianLine.setText(text);
                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    //外检检测开始
    private void getDataWaiJainStart() {
        CarItemStartModel carItemStartModel = new CarItemStartModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
//        data.get(position).getPlateRegion() + data.get(position).getPlateNO()
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setDetectionID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(instances));
        carItemStartModel.setItemCode("F1");
        carItemStartModel.setLeadTruck(Login_name);
        BaseApplication.W_ItemStart_time = "";
        BaseApplication.W_ItemStart_time = DateUtil.currentTime2();
//        carItemStartModel.setDetectionItemStartDate(DateUtil.currentTime2());
        carItemStartModel.setDetectionItemStartDate(BaseApplication.W_ItemStart_time);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);

//        String upjson_url = "{[" + jsonStr.substring(1, jsonStr.length() - 1) + "]}";
        String upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";

        String logStr = "\n" + "外检项目开始----json" + "\n" +
                "json::" + upjson_url + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataWaiJainStart---jsonStr==" + upjson_url);
        UtilsLog.e("getDataWaiJainStart---url==" + SharedPreferencesUtils.getIP(this) + ITEM_START);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_START)
                .tag(this)
                .upJson(upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("getDataWaiJainStart-result==" + result);
                        UtilsLog.e("getDataWaiJainStart-result=22=" + result.substring(1, result.length() -
                                1));
                        String logStr = "\n" + "外检项目开始----请求成功" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        String str = result.substring(1, result.length() - 1);
//                        if ("ok".equalsIgnoreCase(str)) {
                        Intent intent = new Intent(instances, WaiJianPhotoActivity.class);
                        intent.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
                        intent.putExtra("CarDetailsActivity_acCarDetailsWaijianchedao",
                                Line);
                        intent.putExtra("CarDetailsActivity_Line", Line);
                        intent.putExtra("login_w_name", Login_name);
                        intent.putExtra("login_IDNumber", login_IDNumber);
                        intent.putExtra("start_time", BaseApplication.W_ItemStart_time);
                        intent.putExtra("EngineNOFlag", EngineNOFlag);
                        intent.putExtra("jianyi", jianyi);

                        intent.putExtra("dzss", dzss);
                        startActivity(intent);
//                        Intent intent = new Intent(instances, WaiJianPhotoActivity.class);
//                        intent.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
//                        intent.putExtra("CarDetailsActivity_acCarDetailsWaijianchedao",
//                                Line);
//                        intent.putExtra("CarDetailsActivity_Line", Line);
//                        intent.putExtra("login_w_name", Login_name);
//                        intent.putExtra("login_IDNumber", login_IDNumber);
//                        startActivity(intent);
                        finish();
//                        } else {
//                            Toast.makeText(instances, "上线失败，请重试", Toast.LENGTH_LONG)
//                                    .show();
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        String logStr2 = "\n" + "外检项目开始请求--onError" + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                        UtilsLog.e("getDataWaiJainStart-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    String json_str_getOutPhotoItem;
    private List<TypeModel> typeModelList;

    private void getOutPhotoItem() {
        OutPhotoItem model = new OutPhotoItem();
        model.setCarType(carsInforModel.getType());
        model.setPlateType(carsInforModel.getPlateType());
        model.setUsage(carsInforModel.getUsage());
        model.setPlatformSN(carsInforModel.getPlatformSN());
        Gson gson = new Gson();
        json_str_getOutPhotoItem = gson.toJson(model);
        UtilsLog.e("getOutPhotoItem---json_str==" + json_str_getOutPhotoItem);
        UtilsLog.e("getOutPhotoItem---url==" + SharedPreferencesUtils.getIP(this) + WAI_JIAN_PHOTO_ITEM);

        String logStr = "\n" + "哈尔冰地区---获取外检拍照列表----url" + "\n" +
                "json::" + json_str_getOutPhotoItem + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + WAI_JIAN_PHOTO_ITEM;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + WAI_JIAN_PHOTO_ITEM).tag(this)
                .upJson(json_str_getOutPhotoItem)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String logStr = "\n" + "哈尔冰地区---获取外检拍照列表----onSuccess" + "\n" +
                                "result::" + result + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        BaseApplication.msg = result;
//                        UtilsLog.e("getOutPhotoItem-result==" + result);
//                        CommonUtils.hideLoadingDialog(instances);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getOutPhotoItem-newResult==" + newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            typeModelList = new ArrayList<TypeModel>();
                            typeModelList = JsonUtil.stringToArray(newResult,
                                    TypeModel[].class);
                            if (typeModelList != null && typeModelList.size() > 0) {
                                up_json_str = "";
                                for (int i = 0; i < typeModelList.size(); i++) {
                                    up_json_str += typeModelList.get(i).getCode() + "|" + typeModelList.get(i).getName()
                                            + ",";
                                }
                                UtilsLog.e("up_json_str==" + up_json_str.substring(0, up_json_str.length() - 1));
                            }
                        } else {
                            BaseApplication.msg = result;
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        BaseApplication.msg = response.body() + "==" + response.message();
                        UtilsLog.e("getOutPhotoItem-onError==" + response.body());
//                        CommonUtils.hideLoadingDialog(instances);
                        String logStr = "\n" + "哈尔冰地区---获取外检拍照列表----onError" + "\n" +
                                "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }

    //外检检测结束
    String getDataWaiJainEnd_upjson_url;

    private void getDataWaiJainEnd(String endTime) {
        CarItemEndModel carItemStartModel = new CarItemEndModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
        carItemStartModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(instances));
        carItemStartModel.setItemCode(Item_Code);
        BaseApplication.W_ItemEnd_time = "";
        BaseApplication.W_ItemEnd_time = DateUtil.currentTime2();
        carItemStartModel.setDetectionItemEndDate(BaseApplication.W_ItemEnd_time);
//        carItemStartModel.setDetectionItemEndDate(endTime);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);
//        String upjson_url = "{[" + jsonStr.substring(1, jsonStr.length() - 1) + "]}";
        getDataWaiJainEnd_upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";
        UtilsLog.e("getDataWaiJainEnd---jsonStr==" + getDataWaiJainEnd_upjson_url);
        UtilsLog.e("getDataWaiJainEnd---url==" + SharedPreferencesUtils.getIP(this) + ITEM_END);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_END).tag(this)
                .upJson(getDataWaiJainEnd_upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataWaiJainEnd-result==" + result);
                        CommonUtils.hideLoadingDialog(instances);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataWaiJainEnd-newResult==" + newResult);
                        String logStr = "\n" + "外检项目结束--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) + "" +
                                ITEM_END + "\n" + "JSON::" + getDataWaiJainEnd_upjson_url +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                        Toast.makeText(instances, "外检项目完成", Toast
                                .LENGTH_LONG).show();
                        EndAllItem(String.valueOf(carsInforModel.getID()));
                        updateCarStatusInfor(1);

//                        Handler handler = new Handler();
//                        handler.postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//                                //项目总结束
//                                updateCarStatusInfor(1);
//                                EndAllItem(String.valueOf(carsInforModel.getID()));
//                            }
//                        }, 300);//后执行Runnable中的run方法

                        if ("ok".equalsIgnoreCase(newResult)) {
//                            Toast.makeText(instances, "外检项目完成", Toast
//                                    .LENGTH_LONG).show();
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    //项目总结束
//                                    updateCarStatusInfor(1);
//                                    EndAllItem(String.valueOf(carsInforModel.getID()));
//                                }
//                            }, 300);//后执行Runnable中的run方法
                        } else {
                            showDialog("外检平台下线失败，请尝试重新下线");
//                            showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainEnd-onError==" + response.body());
                        String logStr = "\n" + "外检项目结束-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_END + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    AlertDialog.Builder builder = null;

    private void showDialog(String content) {
        AlertDialog.Builder builder = new AlertDialog.Builder
                (instances);
        builder.setTitle("提示");
        builder.setMessage(content);
//        builder.setNegativeButton("取消", null);
        builder.setPositiveButton("确定", null);
        builder.show();
    }

    /**
     * 项目总结束接口,最后一个执行
     */
    private void EndAllItem(final String detectionID) {
        UtilsLog.e("EndAllItem---url==" + SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID");
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID").tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        //完成按钮可点击
                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
                        UtilsLog.e("EndAllItem-result==" + result);
                        String logStr = "\n" + "外检项目总结束:总结束:总结束--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_ALL_END + detectionID + "/DetectionID" +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        acCarDetailsCancle.setEnabled(true);
                        finish();

//                        if ("\"ok\"".equals(result)) {
//
//                            updateCarStatusInfor(1);
//                            Toast.makeText(instances, "外检项目完成", Toast
//                                    .LENGTH_LONG).show();
//
//                        } else {
//                            showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        String logStr = "\n" + "外检项目总结束:总结束:总结束-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_ALL_END + detectionID + "/DetectionID" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        UtilsLog.e("EndAllItem-onError==" + response.body());
                        UtilsLog.e("EndAllItem-onError==" + response.getException());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    String myjson;

    private void getDataReportData() {
        UtilsLog.e("getDataReportData---url==" + SharedPreferencesUtils.getIP(instances) + REPORTED_DATA);
//        myjson = reportedJsonStr();
        myjson = reportedJsonStr3();
        UtilsLog.e("getDataReportData-result=myjson=" + myjson);
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + REPORTED_DATA).tag(instances)
                .upJson(myjson)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataReportData-result==" + result);
                        String logStr = "\n" + "外检上传自己后台数据--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "JSON::" + myjson +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        if ("\"ok\"".equals(result)) {
//                            Toast.makeText(instances, "上报数据成功", Toast.LENGTH_LONG).show();
//                            instances.finish();
                        } else {
                            showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataReportData-onError==" + response.body());
                        UtilsLog.e("getDataReportData-onError==" + response.getException());
                        String logStr = "\n" + "外检上传自己后台数据-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
//                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
//                                .LENGTH_LONG).show();
                        showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    String jsonStr;

    private void updateCarStatusInfor(int flag) {
        UpdateCarStatusModel model = new UpdateCarStatusModel();
        model.setType(0);
        model.setQueueID(String.valueOf(carsInforModel.getID()));
        switch (CHECK_MODE) {
            case 0:
                model.setAppearanceStatus(flag);
                break;
            case 1:
                model.setRoadStatus(flag);
                break;
            case 2:
                model.setDynamicStatus(flag);
                break;
        }
        Gson gson = new Gson();
        jsonStr = gson.toJson(model);
        UtilsLog.e("updateCarStatusInfor---jsonStr==" + jsonStr);
        UtilsLog.e("updateCarStatusInfor---url==" + SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS)
                .tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("updateCarStatusInfor-result==" + result);
                        UtilsLog.e("updateCarStatusInfor-result=22=" + result.substring(1, result.length()
                                - 1));
                        String logStr = "\n" + "外检-车辆详情--更新车辆状态请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS + "\n" + "JSON::" + jsonStr + "\n" + "result::" +
                                response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        String str = result.substring(1, result.length() - 1);
//                        if ("ok".equals(str)) {

//                            Intent intent = new Intent(CarDetailsActivity.this, WaiJianPhotoActivity.class);
//                            intent.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
//                            intent.putExtra("CarDetailsActivity_acCarDetailsWaijianchedao",
//                                    acCarDetailsWaijianchedao
//                                            .getText().toString().trim());
//                            intent.putExtra("CarDetailsActivity_Line", Line);
//                            startActivity(intent);
//                            finish();
//                        } else {
//                            Toast.makeText(CarDetailsActivity.this, "上线失败，请重试", Toast.LENGTH_LONG)
//                                    .show();
//                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainStart-onError==" + response.body());
                        String logStr = "\n" + "外检-车辆详情--更新车辆状态请求失败--error" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //组装要上报的json
    private String reportedJsonStr() {
        String myjson = "";
        ReportedModel model;
        model = new ReportedModel();
        model.setDataType("F1");
        model.setDetection_ID(String.valueOf(carsInforModel.getID()));
        model.setGUID(carsInforModel.getGUID());
        model.setTest_times(carsInforModel.getTimes());
        model.setUnqualified_Code1("0");
        model.setUnqualified_Code2("0");
        model.setUnqualified_Code3("0");
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
        UtilsLog.e("getDataReportData---myjson==" + myjson);

        return myjson;
    }

    //组装要上报的json
    private String reportedJsonStr3() {
        String myjson = "";
//        ReportedModel3 model;
//        model = new ReportedModel3();
//        model.setDataType("F1");
//        model.setDetection_ID(String.valueOf(carsInforModel.getID()));
////        model.setGUID(carsInforModel.getGUID());
//        model.setTest_times(carsInforModel.getTimes());
        CodeListModel codeListModel = null;
        List<CodeListModel> codeList_list = new ArrayList<>();
        if (BaseApplication.BaseApplication_buHeGeModel3List != null
                && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
            //去重
            Utils.removeDuplicate(BaseApplication.BaseApplication_buHeGeModel3List);
            //set集合保存的是引用不同地址的对象
            Set<BuHeGeModel3> ts = new HashSet<BuHeGeModel3>();
            ts.addAll(BaseApplication.BaseApplication_buHeGeModel3List);

            for (BuHeGeModel3 student : ts) {
                UtilsLog.e("BaseApplication_buHeGeModel3List=去重数据=" +
                        BaseApplication.BaseApplication_buHeGeModel3List.toString());
//                System.out.println(student.getId()+"-"+student.getName());
            }

            //去除  IsCheck==1
            for (int i = 0; i < BaseApplication.BaseApplication_buHeGeModel3List.size(); i++) {
                UtilsLog.e("BaseApplication_buHeGeModel3List=原始数据=" +
                        BaseApplication.BaseApplication_buHeGeModel3List.toString());
                if ("1".equals(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getIsCheck())) {
                    BaseApplication.BaseApplication_buHeGeModel3List.remove(i);
                }
            }

            if (BaseApplication.BaseApplication_buHeGeModel3List != null
                    && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
                for (int i = 0; i < BaseApplication.BaseApplication_buHeGeModel3List.size(); i++) {
                    UtilsLog.e("BaseApplication_buHeGeModel3List=去掉IsCheck==1后的数据=" +
                            BaseApplication.BaseApplication_buHeGeModel3List.toString());
                    codeListModel = new CodeListModel();
                    codeListModel.setDataType("F1");
                    codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                    codeListModel.setTest_times(carsInforModel.getTimes());
                    if ("0".equals(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getIsCheck())) {
                        codeListModel.setUnqualified_Code1(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode1());
                        codeListModel.setUnqualified_Code2(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode2());
                        codeListModel.setUnqualified_Code3(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode3());
                    }
                    codeList_list.add(codeListModel);
                }
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("reportedJsonStr3333==" + myjson);
            } else {
                codeListModel = new CodeListModel();
                codeListModel.setDataType("F1");
                codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                codeListModel.setTest_times(carsInforModel.getTimes());
                codeListModel.setUnqualified_Code1("0");
                codeListModel.setUnqualified_Code2("0");
                codeListModel.setUnqualified_Code3("0");
                codeList_list.add(codeListModel);
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("reportedJsonStr4444==" + myjson);
            }
        } else {
            codeListModel = new CodeListModel();
            codeListModel.setDataType("F1");
            codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
            codeListModel.setTest_times(carsInforModel.getTimes());
            codeListModel.setUnqualified_Code1("0");
            codeListModel.setUnqualified_Code2("0");
            codeListModel.setUnqualified_Code3("0");
            codeList_list.add(codeListModel);
            Gson gson = new Gson();
            String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
            myjson = jsonStr;
            UtilsLog.e("reportedJsonStr555==" + myjson);
        }
        return myjson;
    }

    //外检上传平台数据
    String upjson_url;

    private void uploadPlatformData_w(WaiJainDataModel waiJainDataModel) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(waiJainDataModel);
        upjson_url = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," + appendCode2AndValues
                () + "}]";
        UtilsLog.e("uploadPlatformData_w---jsonStr==" + upjson_url);
        UtilsLog.e("uploadPlatformData_w---url==" + SharedPreferencesUtils.getIP(this) + PLAT_FORM_DATA);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + PLAT_FORM_DATA).tag(this)
                .upJson(upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("uploadPlatformData_w-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("uploadPlatformData_w-newResult==" + newResult);
                        if ("ok".equalsIgnoreCase(newResult)) {
                            String logStr = "\n" + "外检上传平台数据--请求成功" +
                                    "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                    PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url +
                                    "\n" + "result::" + result;
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    /**
                                     *要执行的操作
                                     */
                                    getDataWaiJainEnd("");
                                }
                            }, 800);//后执行Runnable中的run方法


                        } else {
                            String logStr = "\n" + "外检上传平台数据--项目结束失败" +
                                    "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                    PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url +
                                    "\n" + "result::" + result;
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                            showDialog("上传平台数据失败，请重试，如果还未成功请联系管理员");
//                            Toast.makeText(WaiJianPhotoActivity.this, "项目结束失败", Toast.LENGTH_LONG)
//                                    .show();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("uploadPlatformData_w-onError==" + response.body());
                        String logStr = "\n" + "外检上传平台数据-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                PLAT_FORM_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("上传平台数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    //拼装json  --Code2
    private String appendCode2AndValues() {
        String Code2JsonStr = "";
        String result = "";
        if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
            for (int i = 0; i < myChoiceModelList.size(); i++) {
                Code2JsonStr = Code2JsonStr + "\"" + myChoiceModelList.get(i).getCode_key() + "\""
                        + ":" + "\"" + myChoiceModelList.get(i).getCode_values() + "\"" + ",";
            }
//            UtilsLog.e("Code2JsonStr==" + Code2JsonStr);
            UtilsLog.e("Code2JsonStr=22=" + Code2JsonStr.substring(0, Code2JsonStr.length() - 1));
        }
        if (Code2JsonStr.length() > 0) {
            result = Code2JsonStr.substring(0, Code2JsonStr.length() - 1);
        }
        return result;
    }


    //获取需要检测的人工检验项目接口
    private void getMyCarItems() {
        ItemsModel model = new ItemsModel();

        model.setCarType(carsInforModel.getType());
        model.setDetectCategroy(carsInforModel.getDetectionCategory());
        model.setPassengerNb(carsInforModel.getApprovedLoad());
        model.setPlateType(carsInforModel.getPlateType());
        model.setVehicleID(String.valueOf(carsInforModel.getVehicleID()));

        String registerTime = carsInforModel.getRegisteDate();
        String str = registerTime.substring(6, registerTime.length() - 2).trim();
        String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
        model.setRegisteDate(registerdate);


//        model.setCarType(carsInforModel.getType());
//        model.setDetectCategroy(carsInforModel.getDetectionCategory());
//        model.setPassengerNb(carsInforModel.getApprovedLoad());
//        model.setPlateType(carsInforModel.getPlateType());
//
//        String registerTime = carsInforModel.getRegisteDate();
//        String str = registerTime.substring(6, registerTime.length() - 2).trim();
//        String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
//        model.setRegisteDate(registerdate);

        Gson gson = new Gson();
        String json_str = gson.toJson(model);
        UtilsLog.e("getMyCarItems---json_str==" + json_str);
        UtilsLog.e("getMyCarItems---url==" + SharedPreferencesUtils.getIP(this) + GET_MY_ITEM_38900);

        String logStr = "\n" + "外检--获取需要检测的人工检验项目接口--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                GET_MY_ITEM_38900 + "\n" + "JSON::" + json_str + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + GET_MY_ITEM_38900).tag(this)
                .upJson(json_str)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getMyCarItems-newResult==" + newResult);
//                        String logStrf = "\n" + "外检--获取需要检测的人工检验项目接口--请求成功" +
//                                "\n" + "result::" + response.body();
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            mycar_checkItemlList = new ArrayList<CheckItemModel>();
                            mycar_checkItemlList = JsonUtil.stringToArray(newResult,
                                    CheckItemModel[].class);
                            if (mycar_checkItemlList != null && mycar_checkItemlList.size() > 0) {
                                List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                                Item_2Model item_2 = null;
                                for (int i = 0; i < mycar_checkItemlList.size(); i++) {
                                    item_2 = new Item_2Model();
                                    item_2.setID(mycar_checkItemlList.get(i).getID());
                                    item_2.setCode1(mycar_checkItemlList.get(i).getCode1());
                                    item_2.setCode2(mycar_checkItemlList.get(i).getCode2());
                                    item_2.setName2(mycar_checkItemlList.get(i).getName2());
                                    Item_2Model_list.add(item_2);
                                }
                                for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                                    for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                        if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k)
                                                .getCode2())) {
                                            Item_2Model_list.remove(j);
                                        }
                                    }
                                }
//
                                for (int i = 0; i < myChoiceModelList.size(); i++) {
//
                                    String Code2 = myChoiceModelList.get(i).getCode2().toString().trim();
                                    for (int j = 0; j < Item_2Model_list.size(); j++) {
                                        String code2_my = Item_2Model_list.get(j).getCode2().toString()
                                                .trim();
                                        if (Code2.equals(code2_my)) {
                                            myChoiceModelList.get(i).setCode_values("1");
                                        }
                                    }
                                }
                            } else {
                                UtilsLog.e("getMyCarItems-Result==没有获取到当前车辆检测到的项目");
                            }
                        } else {
                            UtilsLog.e("getGET_ALL_ITEMList-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getMyCarItems-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "外检--获取需要检测的人工检验项目接口--请求失败--error" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                    }
                });
    }

    private void getDataReportData2() {
        UtilsLog.e("getDataReportData---url==" + SharedPreferencesUtils.getIP(instances) + REPORTED_DATA);
        String myjson = reportedJsonStr();
        String logStr = "\n" + "外检-车辆详情--上报数据请求成功--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                REPORTED_DATA + "\n" + "JSON::" + myjson + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + REPORTED_DATA).tag(instances)
                .upJson(myjson)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataReportData-result==" + result);
                        String logStr = "\n" + "外检-车辆详情--上报数据请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "JSON::" + reportedJsonStr() +
                                "\n" + "result::" + result + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if ("\"ok\"".equals(result)) {
//                            Toast.makeText(instances, "上报数据成功", Toast.LENGTH_LONG).show();
//                            instances.finish();

                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataReportData-onError==" + response.body());
                        UtilsLog.e("getDataReportData-onError==" + response.getException());
                        String logStr = "\n" + "外检-车辆详情--上报数据请求失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "JSON::" + reportedJsonStr() +
                                "\n" + "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
                                .LENGTH_LONG).show();
                    }
                });
    }


    //外扩视频录像开始
    private void waiKuoShiPinStart() {
        CarItemStartModel carItemStartModel = new CarItemStartModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
//        data.get(position).getPlateRegion() + data.get(position).getPlateNO()
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setDetectionID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(instances));
        carItemStartModel.setItemCode("M2");
        BaseApplication.W_ItemStart_time = "";
        BaseApplication.W_ItemStart_time = DateUtil.currentTime2();
//        carItemStartModel.setDetectionItemStartDate(DateUtil.currentTime2());
        carItemStartModel.setDetectionItemStartDate(BaseApplication.W_ItemStart_time);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);

//        String upjson_url = "{[" + jsonStr.substring(1, jsonStr.length() - 1) + "]}";
        String upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";

        String logStr = "\n" + "外扩视频录像开始----json" + "\n" +
                "json::" + upjson_url + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("外扩视频录像开始---jsonStr==" + upjson_url);
        UtilsLog.e("外扩视频录像开始---url==" + SharedPreferencesUtils.getIP(this) + ITEM_START);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_START)
                .tag(this)
                .upJson(upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("外扩视频录像开始-result==" + result);
                        UtilsLog.e("外扩视频录像开始-result=22=" + result.substring(1, result.length() -
                                1));
                        String logStr = "\n" + "外扩视频录像开始----请求成功" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        String str = result.substring(1, result.length() - 1);
//                        if ("ok".equalsIgnoreCase(str)) {
                        Toast.makeText(instances, "外扩视频录像成功", Toast.LENGTH_LONG)
                                .show();
//                        } else {
//                            Toast.makeText(instances, "开始失败，请重试", Toast.LENGTH_LONG)
//                                    .show();
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        String logStr2 = "\n" + "外扩视频录像开始请求--onError" + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                        UtilsLog.e("外扩视频录像开始-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //外扩视频录像结束
    private void waiKuoShiPinEnd() {
        CarItemEndModel carItemStartModel = new CarItemEndModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
        carItemStartModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(instances));
        carItemStartModel.setItemCode("M2");
        BaseApplication.W_ItemEnd_time = "";
        BaseApplication.W_ItemEnd_time = DateUtil.currentTime2();
        carItemStartModel.setDetectionItemEndDate(BaseApplication.W_ItemEnd_time);
//        carItemStartModel.setDetectionItemEndDate(endTime);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);
//        String upjson_url = "{[" + jsonStr.substring(1, jsonStr.length() - 1) + "]}";
        String getDataWaiJainEnd_upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";
        String logStr = "\n" + "外扩视频录像结束----json" + "\n" +
                "json::" + getDataWaiJainEnd_upjson_url + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_END;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataWaiJainEnd---jsonStr==" + getDataWaiJainEnd_upjson_url);
        UtilsLog.e("getDataWaiJainEnd---url==" + SharedPreferencesUtils.getIP(this) + ITEM_END);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_END).tag(this)
                .upJson(getDataWaiJainEnd_upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("外扩视频录像结束-result==" + result);
                        CommonUtils.hideLoadingDialog(instances);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("外扩视频录像结束-newResult==" + newResult);
                        String logStr = "\n" + "外扩视频录像结束--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) + "" +
                                ITEM_END + "\n" + "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());


//                        if ("ok".equalsIgnoreCase(newResult)) {
                        Toast.makeText(instances, "外扩视频录像完成", Toast
                                .LENGTH_LONG).show();
//                        } else {
//                            Toast.makeText(instances, "外扩视频录像结束失败，请重试", Toast
//                                    .LENGTH_LONG).show();
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        CommonUtils.hideLoadingDialog(instances);
                        UtilsLog.e("外扩视频录像结束-onError==" + response.body());
                        String logStr = "\n" + "外扩视频录像结束-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_END + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        Toast.makeText(instances, "外扩视频录像结束失败，请重试", Toast
//                                .LENGTH_LONG).show();
                    }
                });
    }


    //天津---查询车辆报告
    private void tianJin_getCarReport() {
        TianJinCarReport modle = new TianJinCarReport();
        modle.setBrand(carsInforModel.getBrand());
        modle.setCarModel(carsInforModel.getCarModel());
        modle.setPDAType("PDA");
        modle.setBH("");
        if (isNewPlat){
            modle.setIsNew("1");
            modle.setUseProperty(carsInforModel.getUseProperty());
            modle.setVechileType(carsInforModel.getType());
        }
        Gson gson = new Gson();
        String jsonStr = gson.toJson(modle);
        String logStr = "\n" + "天津---查询车辆报告---" + "\n" +
                "json::" + jsonStr + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + GET_CAR_REPORT;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("天津---查询车辆报告---jsonStr==" + jsonStr);
        UtilsLog.e("天津---查询车辆报告---url==" + SharedPreferencesUtils.getIP(this) + GET_CAR_REPORT);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + GET_CAR_REPORT)
                .tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances,"加载中...");
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        String result = response.body().trim();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("天津---查询车辆报告-result==" + result);
                        UtilsLog.e("天津---查询车辆报告-newResult==" + newResult);
//                        UtilsLog.e("天津---查询车辆报告-result=22=" + result.substring(1, result.length() -
//                                1));
                        String logStr = "\n" + "天津---查询车辆报告----请求成功" + "\n" +
                                "result::" + response.body() + "\n" + "newResult::" + newResult + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        newResult = "[{\"sjbs\":\"01\",\"result\":[{\"ggzpList\":[{\"sxh\":1,\"zpbh\":\"1510861975\",\"bh\":\"SV160601004105\"},{\"sxh\":2,\"zpbh\":\"1510861989\",\"bh\":\"SV160601004105\"}],\"zcggObj\":{\"zxxs\":\"1\",\"sfmj\":\"1\",\"zzcmc\":\"上汽大众\",\"jyw\":\"3\",\"clpp2\":\"V\",\"gbthps\":\"-/-\",\"clpp1\":\"大众\",\"cplb\":\"1\",\"yh\":\"6.80\",\"fdjxh\":\"D\",\"clmc\":\"轿车\",\"sfxny\":\"2\",\"sbdhxl\":\"LS\",\"ggbj\":\"1\",\"hbdbqk\":\"GB18352.5-2013国Ⅴ\",\"cxsxrq\":\"20\",\"qzdfs\":\"0\",\"cllx\":\"K33\",\"hdzk\":\"5\",\"clggbh\":\"20151008000107\",\"dpqyxh\":\"承载式车身\",\"qzdczfs\":\"0\",\"zzg\":\"156\",\"zzl\":\"2100\",\"hzdfs\":\"0\",\"qlj\":\"1577\",\"zh\":\"10\",\"ggrq\":\"\",\"cxggrq\":\"202\",\"zj\":\"2803\",\"cdxs\":\"0\",\"clxh\":\"SVW71810BU\",\"zs\":\"2\",\"gxrq\":\"00\",\"jjlqj\":\"15/13\",\"qxhx\":\"919/1150\",\"bh\":\"SV160601004105\",\"sfyxzc\":\"0\",\"tzscrq\":\"800\",\"cslx\":\"2\",\"scdz\":\"江苏省南\",\"bz\":\"选\",\"rlzl\":\"A\",\"ltgg\":\"V\",\"ggyxqbj\":\"3\",\"jsslx\":\"0\",\"ggsxrq\":\"2016-05-20T00:00:00\",\"cwkc\":\"2\",\"zbzl\":\"0\",\"zgcs\":\"5\",\"gl\":\"1\",\"hlj\":\"1\",\"lts\":\"4\",\"hzdczfs\":\"0\",\"pc\":\"2\",\"cxggpc\":\"3\",\"ywabs\":\"1\",\"qyid\":\"G\",\"cwkk\":\"34\",\"pl\":\"1\",\"zps\":\"5\",\"cwkg\":\"1\"}}]}]".substring(1, result.length() - 1).replaceAll("\\\\", "");
//                        Log.e("tag", "newResult11111==="+newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
//                            Log.e("tag", "newResult22222==="+newResult);
                            if (isNewPlat) {
                                try {
                                    JSONArray jsonArray = new JSONArray(newResult);
                                    String finalResult = jsonArray.toString();
                                    String logStr2 = "\n" + "天津---查询车辆报告----请求成功" + "\n" +
                                            "finalResult::" + finalResult + "\n";
                                    Log.e("tag", "天津---查询车辆报告----finalResult====" + finalResult);
                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                    Toast.makeText(instances, "查询成功", Toast.LENGTH_LONG)
                                            .show();
                                    Intent intent = new Intent(instances, TianjinReportActivity.class);
                                    intent.putExtra("tianjinReport", finalResult);
                                    intent.putExtra("plateNo", carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
                                    intent.putExtra("isNewPlat", true);
                                    startActivity(intent);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                try {
                                    JSONObject jsonObject = new JSONObject(newResult);
                                    String finalResult = jsonObject.getJSONObject("root").getJSONObject("body").toString();
                                    String logStr2 = "\n" + "天津---查询车辆报告----请求成功" + "\n" +
                                            "finalResult::" + finalResult + "\n";
                                    Log.e("tag", "天津---查询车辆报告----finalResult====" + finalResult);
                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                    Toast.makeText(instances, "查询成功", Toast.LENGTH_LONG)
                                            .show();
                                    Intent intent = new Intent(instances, TianjinReportActivity.class);
                                    intent.putExtra("tianjinReport", finalResult);
                                    intent.putExtra("plateNo", carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
                                    intent.putExtra("isNewPlat", false);
                                    startActivity(intent);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }

                        }
//                        CommonUtils.hideLoadingDialog(instances);
//                        String str = result.substring(1, result.length() - 1);
////                        if ("ok".equalsIgnoreCase(str)) {

//                        } else {
//                            Toast.makeText(instances, "开始失败，请重试", Toast.LENGTH_LONG)
//                                    .show();
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        String logStr2 = "\n" + "天津---查询车辆报告--onError" + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                        UtilsLog.e("天津---查询车辆报告-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    class TianJinCarReport {
        String Brand, CarModel, BH, PDAType, IsNew, VechileType, UseProperty;

        public String getBH() {
            return BH;
        }

        public void setBH(String BH) {
            this.BH = BH;
        }

        public String getPDAType() {
            return PDAType;
        }

        public void setPDAType(String PDAType) {
            this.PDAType = PDAType;
        }

        public String getBrand() {
            return Brand;
        }

        public void setBrand(String brand) {
            Brand = brand;
        }

        public String getCarModel() {
            return CarModel;
        }

        public void setCarModel(String carModel) {
            CarModel = carModel;
        }

        public String getIsNew() {
            return IsNew;
        }

        public void setIsNew(String isNew) {
            IsNew = isNew;
        }

        public String getVechileType() {
            return VechileType;
        }

        public void setVechileType(String vechileType) {
            VechileType = vechileType;
        }

        public String getUseProperty() {
            return UseProperty;
        }

        public void setUseProperty(String useProperty) {
            UseProperty = useProperty;
        }

        @Override
        public String toString() {
            return "TianJinCarReport{" +
                    "Brand='" + Brand + '\'' +
                    ", CarModel='" + CarModel + '\'' +
                    ", BH='" + BH + '\'' +
                    ", PDAType='" + PDAType + '\'' +
                    ", IsNew='" + IsNew + '\'' +
                    ", VechileType='" + VechileType + '\'' +
                    ", UseProperty='" + UseProperty + '\'' +
                    '}';
        }
    }

}
